﻿

using DualPlaneFR4Paster.Common.Events;
using DualPlaneFR4Paster.Common.Services;
using DualPlaneFR4Paster.Models;
using Prism.Events;
using Prism.Services.Dialogs;
using System;
using System.Threading.Tasks;

namespace DualPlaneFR4Paster.Extensions
{
    public static class DialogExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dialogHost">指定的DialogHost会话主机</param>
        /// <param name="type">消息框类型</param>
        /// <param name="caption">消息框窗口名</param>
        /// <param name="contain">消息内容</param>
        /// <returns>返回对话框结果</returns>
        public static ButtonResult MessageBox(this IDialogHostService dialogHost, MessageType type,string caption,string contain)
        {
            DialogParameters param = new DialogParameters();
            param.Add("MessageType", type);
            param.Add("MsgCaption", caption);
            param.Add("MsgContain", contain);
            var dialogResult = dialogHost.ShowDialog("MessageBoxDialog", param);
            return dialogResult;
        }
        /// <summary>
        /// 密码输入窗口
        /// </summary>
        /// <param name="dialogHost">指定的DialogHost会话主机</param>
        /// <param name="title">标题</param>
        /// <returns>返回对话框结果</returns>
        public static ButtonResult Password(this IDialogHostService dialogHost, string title)
        {
            DialogParameters param = new DialogParameters();
            param.Add("Title", title);
            var dialogResult = dialogHost.ShowDialog("PasswordDialog", param);
            return dialogResult;
        }
        /// <summary>
        /// 注册提示消息 
        /// </summary>
        /// <param name="aggregator"></param>
        /// <param name="action"></param>
        public static void ResgiterMessage(this IEventAggregator aggregator,
            Action<MessageModel> action, string filterName = "Main")
        {
            aggregator.GetEvent<MessageEvent>().Subscribe(action,
                ThreadOption.PublisherThread, true, (m) =>
                {
                    return m.Filter.Equals(filterName);
                });
        }
        /// <summary>
        /// 发送提示消息
        /// </summary>
        /// <param name="aggregator"></param>
        /// <param name="message"></param>
        public static void SendMessage(this IEventAggregator aggregator, string message, string filterName = "Main")
        {
            aggregator.GetEvent<MessageEvent>().Publish(new MessageModel()
            {
                Filter = filterName,
                Message = message,
            });
        }
    }
}
